package com.baizhi.service.impl;

import com.baizhi.mapper.ShopMapper;
import com.baizhi.mapper.UserAndRoleMapper;
import com.baizhi.pojos.Shop;
import com.baizhi.pojos.User;
import com.baizhi.pojos.UserAndRole;
import com.baizhi.service.ShopService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {

    @Autowired
    private UserAndRoleMapper userAndRoleMapper;

    @Override
    public Map<String, Object> findList(User user) {

        Map<String, Object> map = new HashMap<>();

        //进行角色查询
        QueryWrapper<UserAndRole> wrapper = new QueryWrapper<>();

        wrapper.lambda().eq(UserAndRole::getUid,user.getUid());

        UserAndRole userAndRole = userAndRoleMapper.selectOne(wrapper);

        map.put("userAndRole",userAndRole);

        //进行商品查询 rid为1是运营 2是管理员
        if (userAndRole.getRid().equals(1)){

            QueryWrapper<Shop> shopQueryWrapper = new QueryWrapper<>();

            shopQueryWrapper.lambda().eq(Shop::getStatus,"0");

            List<Shop> list = list(shopQueryWrapper);

            map.put("shop",list);
        }else {

            QueryWrapper<Shop> shopQueryWrapper = new QueryWrapper<>();

            shopQueryWrapper.lambda().in(Shop::getStatus,"1","2","3","4","5");

            List<Shop> list = list(shopQueryWrapper);

            map.put("shop",list);
        }

        return map;
    }
}
